package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.AOpenlock;
import com.ruoyi.lock.service.IAOpenlockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 开门记录Controller
 * 
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/lock/openlock")
public class AOpenlockController extends BaseController
{
    @Autowired
    private IAOpenlockService aOpenlockService;

    /**
     * 查询开门记录列表
     */
    @PreAuthorize("@ss.hasPermi('lock:openlock:list')")
    @GetMapping("/list")
    public TableDataInfo list(AOpenlock aOpenlock)
    {
        startPage();
        List<AOpenlock> list = aOpenlockService.selectAOpenlockList(aOpenlock);
        return getDataTable(list);
    }

    /**
     * 导出开门记录列表
     */
    @PreAuthorize("@ss.hasPermi('lock:openlock:export')")
    @Log(title = "开门记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AOpenlock aOpenlock)
    {
        List<AOpenlock> list = aOpenlockService.selectAOpenlockList(aOpenlock);
        ExcelUtil<AOpenlock> util = new ExcelUtil<AOpenlock>(AOpenlock.class);
        util.exportExcel(response, list, "开门记录数据");
    }

    /**
     * 获取开门记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:openlock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aOpenlockService.selectAOpenlockById(id));
    }

    /**
     * 新增开门记录
     */
    @PreAuthorize("@ss.hasPermi('lock:openlock:add')")
    @Log(title = "开门记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AOpenlock aOpenlock)
    {
        return toAjax(aOpenlockService.insertAOpenlock(aOpenlock));
    }

    /**
     * 修改开门记录
     */
    @PreAuthorize("@ss.hasPermi('lock:openlock:edit')")
    @Log(title = "开门记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AOpenlock aOpenlock)
    {
        return toAjax(aOpenlockService.updateAOpenlock(aOpenlock));
    }

    /**
     * 删除开门记录
     */
    @PreAuthorize("@ss.hasPermi('lock:openlock:remove')")
    @Log(title = "开门记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aOpenlockService.deleteAOpenlockByIds(ids));
    }
}
